package com.object.dao.sys;

import com.object.module.lq.sys.entity.TTableEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface TTableDao
{

    @Select({
            "<script>",
            "SELECT t.TABLE_NAME AS table_name, t.table_comment AS comment  FROM information_schema.`TABLES` t WHERE t.TABLE_SCHEMA = ( SELECT DATABASE ( ) )",
            "<if test='tableName!=null'>where t.TABLE_NAME=#{tableName}</if>",
            "</script>"})
    List<TTableEntity> list(@Param("tableName") String tableName);

    @Select({
            "       select\n" +
                    "            t.table_name               ,\n" +
                    "            t.table_comment            ,\n" +
                    "            c.column_name              ,\n" +
                    "            c.column_comment           ,\n" +
                    "            c.ordinal_position         ,\n" +
                    "            c.column_default           ,\n" +
                    "            c.is_nullable              ,\n" +
                    "            c.data_type                ,\n" +
                    "            c.character_maximum_length ,\n" +
                    "            c.numeric_precision        ,\n" +
                    "            c.numeric_scale            ,\n" +
                    "            c.column_type              ,\n" +
                    "            c.column_key 'KEY',\n" +
                    "                c.extra\n" +
                    "        from information_schema. tables t\n" +
                    "                 left join information_schema. columns c\n" +
                    "                           on t.table_name = c.table_name\n" +
                    "                               and t.table_schema = c.table_schema\n" +
                    "        where t.table_schema = DATABASE() and t.table_name=#{tableName}\n" +
                    "        order by c.table_name, c.ordinal_position;"
    })
    List<Map<String, Object>> byTableNameSelect(@Param("tableName") String tableName);
}